package com.wc.AlgoOJ.SQ1201;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2024/1/11 18:06
 * @description 小A的糖果
 * 就是让右边的人吃，贡献为2
 * http://43.138.190.70:8888/p/SQ1201
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] candies = new int[n];
        for (int i = 0; i < n; i++) {
            candies[i] = sc.nextInt();
        }
        System.out.println(minCandies(candies,x));
    }

    public static long minCandies(int[] candies, int x) {
        long minEat = 0;
        for (int i = 0; i < candies.length - 1; i++) {
            if (candies[i] + candies[i + 1] > x) {
                int eat = candies[i] + candies[i + 1] - x;
                minEat += eat;
                candies[i + 1] = Math.max(0, candies[i + 1] - eat);
            }
        }
        return minEat;
    }
}
